package main

import (
	"fmt"
	"github.com/micro/go-micro/registry"
	"github.com/micro/go-plugins/registry/etcdv3"
)

func main() {
	regi := etcdv3.NewRegistry()
	err := regi.Register(&registry.Service{
		Name:      "server-1",
		Version:   "1.0.0",
		Metadata: map[string]string{"name":"zhangsan"},

		//声明方法
		Endpoints: []*registry.Endpoint{{
			Name:     "Greeter.Hello",    // 方法名

			// 请求参数
			Request:  &registry.Value{Name:"HelloRequest",Type:"HelloRequest",Values:[]*registry.Value{{
				Name:   "name",
				Type:   "string",
			}}},

			//响应参数
			Response: &registry.Value{
				Name:   "HelloResponse",
				Type:   "HelloResponse",
				Values: []*registry.Value{{
					Name:   "greeting",
					Type:   "string",
				}},
			},
			Metadata: map[string]string{"stream":"false"},
		}},

		// 服务节点地址
		Nodes:     []*registry.Node{{
			Id:       "greeter-605a9308-2b42-4688-8687-84f64c254a3b",
			Address:  "172.17.0.1",
			Port:     41183,
			Metadata: map[string]string{"protocol":"mucp"},
		}},
	}, func(options *registry.RegisterOptions) {
		fmt.Println(options)
	})

	if err != nil {
		fmt.Errorf("%v",err)
	}
}
